package com.java.control.impl;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;

import com.java.control.AbstractAdminFormController;
import com.java.entity.Supplier;
import com.java.service.SupplierService;

/**
 * 产品添加
 * @author wqf
 * @version  Nov 23, 2011 1:10:42 PM
 */
public class SupplierEditController extends AbstractAdminFormController{

	public SupplierEditController(){
		this.setCommandClass(Supplier.class);
	}
		
	protected void addSubmit(HttpServletRequest request,HttpServletResponse response, Object command, BindException errors) throws Exception {
		Supplier supplier = (Supplier)command;
		
		this.supplierService.editSupplier(supplier);
		request.setAttribute("operation", "add");
	}	
	
	protected void modifySubmit(HttpServletRequest request,HttpServletResponse response,Object command,BindException errors) throws Exception{		
		Supplier supplier = (Supplier)command;
		
		this.supplierService.editSupplier(supplier);
		
		request.setAttribute("operation", "modify");
		request.setAttribute("id", supplier.getId());
	}
		
	protected Object getCommandDataForModify(HttpServletRequest request){
		Long id=Long.valueOf(request.getParameter("id"));
		Supplier supplier = this.supplierService.getSupplierById(id);
		
		return supplier;
	}
	
	protected Object getCommandDataForAdd(HttpServletRequest request) {
		Supplier supplier = new Supplier();
		
		return supplier;
	}
	
	
	public SupplierService getSupplierService() {
		return supplierService;
	}

	public void setSupplierService(SupplierService supplierService) {
		this.supplierService = supplierService;
	}
	
	public SupplierService supplierService;

	
}
